package com.hongling.uc.ons.producer;

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import org.springframework.beans.factory.annotation.Value;

import java.util.Properties;
/**
 * @author Icy.Li
 * @date: 2019/7/30 15:30
 * @description: 创建一个生产者类，此处填入配置文件中的常量类，然后调用getproduce方法时启动生产者 producer.start()
 */
public class CloudMQUtil {
    @Value("${ons.producer.id.transaction}")
    private static String PRODUCER_ID;
    @Value("${ons.access.key}")
    private static String ACCESS_KEY;
    @Value("${ons.secret.key}")
    private static String SECRET_KEY;
    /**
     * 获取消息的 Producer
     *
     * @return Producer
     */
    public static Producer getProducer() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.ProducerId, "PID-HL-UC-DEV-1");
        properties.put(PropertyKeyConst.AccessKey, "N4Few3hRb4QzeeHd");
        properties.put(PropertyKeyConst.SecretKey, "ZI1jzqYeKlla7gx4P7C42sTIUKfCWB");
    /*    properties.put(PropertyKeyConst.ProducerId, PRODUCER_ID);
        properties.put(PropertyKeyConst.AccessKey, ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, SECRET_KEY);*/
        Producer producer = ONSFactory.createProducer(properties);
 
        // 在发送消息前，必须调用start方法来启动Producer，只需调用一次即可。
        producer.start();
        return producer;
    }
 
 
 
 
}